<?php

class Model_HairBlogIndex extends Model {

    function __construct() {
        
    }

    function getList($h_param = array()) {
        $type = $h_param['type'];

        $type_mid_array = $h_param['datas'];
        if (!$type || $type > 3 || $type < 1)
            return array();
        //$page = $h_param['page'] ? $h_param['page'] : 1;
        //$size = 999;

        /* //$type1_blog_name_array = array("bibob","amyleung","heidilee","yankiki","joanie","kitty1230","kanix","sky0721","tiffanyyau","ice198322","viannkiko","kellychingwy","crazyahmin","bee","cindy214","coombe","siumbbx2","szekaijessicayu","fungling","amazinggrace","armui","lazycc","winwinc","luvyan1314","olsenbabi","cherryastor");
        $type_mid_array[1] = "2831, 1513, 1479, 1086, 1494, 9104, 3863, 2724, 738, 1781, 7635, 6022, 985, 1924, 5810, 8359, 7026, 4879, 7705, 212, 6276, 2207, 7536, 65, 3838,7268";
        //$type2_blog_name_array = array("aninaho","ritzlam","willor","rose","vincy","rachellam");
        $type_mid_array[2] = "12926, 9069, 8970, 8971, 12927, 12928";
        //$type3_blog_name_array = array("kelvinkan","kolenbut","jaden","joseph","williamchow","jamie318");
        $type_mid_array[3] = "9082,12929,9070,12930,12931,9206"; */

        $db = "(select id,mid,title,addtime,is_blog from product_reports order by addtime desc)";
        $where = "TB2.blog_name in (" . $type_mid_array[$type] . ") and TB1.is_blog=1";

        $param = array();
        $param['field'] = "TB1.*,TB2.blog_name";
        $param['where'] = $where;
        $param['order'] = "TB1.addtime desc";
        $param['group'] = "TB1.mid";
        $param['limit'] = "";
        //$param['pagesize'] = $size;
        //$param['page'] = $page;
        $param['join'] = "LEFT JOIN blog_users";
        $param['on'] = "TB1.mid = TB2.mid";
        $data = db_query_hash($db, $param);

        return $data;
    }

    function getImoreBlogList($h_param = array()) {
        $type = $h_param['type'];
        $dateflag = $h_param['dateflag'];

        $type_mid_array = $h_param['datas'];
        if (!$type || $type > 3 || $type < 1)
            return array();
        $page = $h_param['page'] ? $h_param['page'] : 1;
        $size = $h_param['size'] ? $h_param['size'] : 999;

        /* $type_mid_array[1] = '"meling","jane-fiesta","leliachow","janey","koeysung","shirleyfoo","elawwong","lamyi","koby","ritzlam","jaden","joseph","willor","rose","daizyland","aninaho","kolenbut","rachellam","jamie318","kelvinkan","deilsiu","tabokiss"';
        //$type_mid_array[1] = "9082,12926,9069,8970,8971,12928,12929,9070,12930,9206";
        $type_mid_array[2] = '"mandytam","isischiu","dominique","monit","kellyliu","kauriyau"';
        //$type_mid_array[2] = "38,40,9194,9097,8120";
        $type_mid_array[3] = '"ben","vickiechan","dotdot","kaye","happy","kittyfung","yuetyee","blurryclaire","daisymarisfung","glamorouskam","alice","candy","candyyip","fungling","waterfish","helloiris","juneleung","snoopyvivi","annak","ahfa","berrychui","irene","katherine","mnwl","vinciyip","wengichow","amazinggrace","stellastella","gillianwai","juan","beautyhunter","wingmiracle","beckylau","mokbb","chanlailate","elyse214","heratoftheocean","manman811","wawa","juliaa","dingdingchan","maxine","siua","wkykam","chicmanman","cherryastor","mayel","cherrietam1204","yankiki","bibob","tatachow","moniquelau","popobb","smallbird1111","kammy41","celiaau","yeeki212","komichan"';
        //$type_mid_array[3] = "47,8020,403,4913,5132,5813,2718,6773,601,1299,6025,513,405,30,458,7302,7617,11335,9458,10454,197,11916,7148,8141,7096,101,8787,5683,5680,9104,12159,12074,12581,7914,10700,12348,11675,10599,198,12013,1494,2831,3838,1781"; */

        $db = "(select id,mid,title,addtime,is_blog from product_reports order by addtime desc)";
        //$where = "TB1.mid in (" . $type_mid_array[$type] . ") and TB1.is_blog=1";
		$where = "TB2.blog_name in (" . $type_mid_array[$type] . ") and TB1.is_blog=1";

        if ($dateflag) {
            switch ($dateflag) {
                case 1:
                    $where.=" and TB1.addtime > date_sub(now(),INTERVAL 1 DAY)";

                    break;
                case 2:
                    $where.=" and TB1.addtime between  date_sub(now(),INTERVAL 1 DAY) and date_sub(now(),INTERVAL 2 DAY)";

                    break;
                case 3:
                    $where.=" and TB1.addtime between date_sub(now(),INTERVAL 2 DAY) and date_sub(now(),INTERVAL 3 DAY)";

                    break;

                default:
                    break;
            }
        }
        $param = array();
        $param['field'] = "TB1.*,TB2.blog_name";
        $param['where'] = $where;
        $param['order'] = "TB1.addtime desc";
        $param['group'] = "TB1.mid";
        $param['limit'] = "";
        $param['pagesize'] = $size;
        $param['page'] = $page;
        $param['join'] = "LEFT JOIN blog_users";
        $param['on'] = "TB1.mid = TB2.mid";
        $data = db_query_hash($db, $param);

        return $data;
    }

    function getBlog($h_param = array()) {
        $result = array();
        $blog_name = $h_param['blog_name'] ? $h_param['blog_name'] : "";
        $blog_id = $h_param['blog_id'] ? $h_param['blog_id'] : 0;
        $category = $h_param['category'] ? $h_param['category'] : 0;

        if (empty($blog_id) && empty($blog_name)) {
            return array();
        }
        if (empty($blog_id) && !empty($blog_name)) {
            $where = "TB2.blog_name='" . $blog_name . "' and TB1.is_blog=1";
            if ($category)
                $where .=" and TB1.id in (select rid from blog_otm_category where cid=" . $category . " order by rid desc)";
            $param = array();
            $param['field'] = "";
            $param['where'] = $where;
            $param['order'] = "TB1.addtime desc,TB1.id desc  "; //"id asc"
            $param['group'] = "";
            $param['limit'] = "";
            $param['pagesize'] = 1;
            $param['page'] = 1;
            $param['join'] = "left join blog_users";
            $param['on'] = "TB1.mid = TB2.mid";
            $data = db_query_hash('product_reports', $param);
        } elseif (!empty($blog_id)) {
            $where = "is_blog=1 and id=" . $blog_id;
            
            $param = array();
            $param['field'] = "";
            $param['where'] = $where;
            $param['order'] = "addtime desc"; //"id asc"
            $param['group'] = "";
            $param['limit'] = "";
            $param['pagesize'] = 1;
            $param['page'] = 1;
            $param['join'] = "";
            $param['on'] = "";
            $data = db_query_hash('product_reports', $param);
        }
        if ($data['result']) {
            if ($data['result'][0]) {

                $where = "status=1 and is_blog=1  and  id<" . $data['result'][0]['id'];

                $where .=" and mid=" . intval($data['result'][0]['mid']);
                if ($category)
                    $where .=" and id in (select rid from blog_otm_category where cid=" . $category . " and rid<" . $data['result'][0]['id']." order by rid desc )";

                $param = array();
                $param['field'] = "id,title";
                $param['where'] = $where;
                $param['order'] = 'id desc'; //"id asc"
                $param['group'] = "";
                $param['limit'] = "1";
                $param['pagesize'] = '';
                $param['page'] = '';
                $param['join'] = "";
                $param['on'] = "";
                $dataNext = db_query_hash('product_reports', $param);

                $data['next'] = array();
                if ($dataNext['result'])
                    $data['result'][0]['next'] = $dataNext['result'][0];

                $where = "status=1  and is_blog=1  and id>" . $data['result'][0]['id'];
                $where .=" and mid=" . intval($data['result'][0]['mid']);
                if ($category)
                    $where .=" and id in (select rid from blog_otm_category where cid=" . $category . " and rid>" . $data['result'][0]['id']." order by rid asc )";

                $param = array();
                $param['field'] = "id,title";
                $param['where'] = $where;
                $param['order'] = 'id asc'; //"id asc"
                $param['group'] = "";
                $param['limit'] = "1";
                $param['pagesize'] = '';
                $param['page'] = '';
                $param['join'] = "";
                $param['on'] = "";
                $dataPrevious = db_query_hash('product_reports', $param);
                $data['previous'] = array();
                if ($dataPrevious['result'])
                    $data['result'][0]['previous'] = $dataPrevious['result'][0];
            }
            $result = $data['result'];
        }

        return $result;
    }

    function getRecentPosts($h_param = array()) {
        $blog_name = $h_param['blog_name'];

        if (empty($blog_name)) {
            return array();
        }
        $param = array();
        $param['field'] = "TB1.id,TB1.title";
        $param['where'] = "TB2.blog_name='" . $blog_name . "' and TB1.is_blog=1";
        $param['order'] = "TB1.addtime desc"; //"id asc"
        $param['group'] = "";
        $param['limit'] = 5;
        $param['pagesize'] = "";
        $param['page'] = "";
        $param['join'] = "left join blog_users";
        $param['on'] = "TB1.mid = TB2.mid";
        $data = db_query_hash('product_reports', $param);

        return $data;
    }

    function getMemberInfo($h_param = array()) {
        $result = array();
        $blog_name = $h_param['blog_name'];

        if (empty($blog_name)) {
            return array();
        }
        $param = array();
        $param['field'] = "bid,mid";
        $param['where'] = "blog_name='" . $blog_name . "'";
        $param['order'] = ""; //"id asc"
        $param['group'] = "";
        $param['limit'] = 1;
        $param['pagesize'] = "";
        $param['page'] = "";
        $param['join'] = "";
        $param['on'] = "";
        $data = db_query_hash('blog_users', $param);

        if ($data['result']) {
            $result['mid'] = $data['result'][0]['mid'];
            $bid = $data['result'][0]['bid'];
            $param = array();
            $param['field'] = "option_name,option_value";
            $param['where'] = "option_id in (2,3)";
            $param['order'] = "option_id asc"; //"id asc"
            $param['group'] = "";
            $param['limit'] = 2;
            $param['pagesize'] = "";
            $param['page'] = "";
            $param['join'] = "";
            $param['on'] = "";
            $data_options = db_query_hash('wp_' . $bid . '_options', $param, IMOREBLOGDB);
            //echo '<pre>' . var_export($data_options, 1) . '</pre>';
            if ($data_options['result']) {
                $result['blogdescription'] = $data_options['result'][1]['option_value'];
                $result['blog_name'] = $data_options['result'][0]['option_value'];
            }
        }

        return $result;
    }

}

?>